﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        SqlConnection con = new SqlConnection();
    con.ConnectionString = ConfigurationManager.ConnectionStrings
                      ["SQLConnectionString"].ConnectionString;
 
// Create SQL Command 
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Select Name,Price,Image,Stocked,Description from _Product where PID =@PID";
    cmd.CommandType = System.Data.CommandType.Text;
    cmd.Connection = con;
    SqlParameter PID = new SqlParameter
                    ("@PID", System.Data.SqlDbType.VarChar);
    PID.Value = context.Request.QueryString["PID"];
    cmd.Parameters.Add(PID);
    con.Open();
    SqlDataReader dReader = cmd.ExecuteReader();
    dReader.Read();
    context.Response.BinaryWrite((byte[])dReader["Image"]);
    dReader.Close();
    con.Close();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}